/****************************************************************************
**
****************************************************************************/

#include <QApplication>
#include <QTranslator>
//#include "EnvironmentIf.h"
//#include "mainwindow.h"
#include<QTreeWidget>
#include <QHeaderView>
#include "cacsiagent.h"
#include <qdebug.h>
#include <QString>
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    //Q_INIT_RESOURCE(dockwidgets);
    //CEnvironmentIf env;
    //QTranslator qtTrans;
    //string qmstdname;
    //env.GetQmFilePath("login_dialog_gbk",qmstdname);
    //QString qmname = QString(qmstdname.c_str());
    //int index = qmname.lastIndexOf(QString(CEnvironmentIf::GetFileSeparator()));

    //if(qtTrans.load(qmname.mid(index + 1, qmname.length()), qmname.mid(0, index)))
    //{
    //    app.installTranslator(&qtTrans);
    //}


    //MainWindow mainWin;
    //mainWin.show();
    //if(Acsi_Init() < 0)
    //{
    //    printf("\nAcsi_Init() err\n");
    //    return 0;
    //}
    QString iedname, iedip;

    if (argc != 3)
    {
        qDebug() << "Please Input IedName and IedIp";
        return -1;
    }
    else
    {
        iedname = QLatin1String(argv[1]);
        iedip = QLatin1String(argv[2]);
        qDebug() << "IED name:" << iedname << "IED ip:" << iedip;
    }
    CAcsiAgent* acsiAgent = new CAcsiAgent();
    acsiAgent->AssociateDevice(iedname.toStdString().c_str(),
                               iedip.toStdString().c_str());

    acsiAgent->GetServerDirectory(ACSI_LOGIC_DEVICE);
    QTreeWidgetItem *root = new QTreeWidgetItem(QStringList() << "" << "");
    root->setText(0, "IED");
    acsiAgent->GetServerModel(root);
    QTreeWidget tree;
    QStringList headers;
    headers << QObject::tr("Context") << QObject::tr("Values");
    tree.setHeaderLabels(headers);
    tree.header()->setResizeMode(QHeaderView::ResizeToContents );
    tree.header()->setStretchLastSection( true);
    tree.setColumnCount(2);
    tree.addTopLevelItem(root);
    tree.show();
    return app.exec();
}
